
var xmlHttp;

function onWriteProduction(id, version, quantity, date) {
	if(version == "") {
		alert("版本号不能为空");
		return;
	} else if(quantity == 0 || quantity == "") {
		alert("添单数量不能为空");
		return;
	} else if(date == "") {
		alert("添单日期不能为空");
		return;
	}
	
	if(xmlHttp = GetXmlHttpObject()) {
		var url = "insertWriteProduction.php";
		url = url + "?id=" + id;
		url = url + "&version=" + version;
		url = url + "&quantity=" + quantity;
		url = url + "&date=" + date;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = writeProductionStateChanged;
		xmlHttp.open("POST", url, true);
		xmlHttp.send(url);
	}
}

function writeProductionStateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("record").innerHTML = trimStr(xmlHttp.responseText);
		document.getElementById("version").value = "";
		document.getElementById("quantity").value = "";
		document.getElementById("date").value = getCurrDate();
	}
}


function onAddNewProject(param) {
	if(xmlHttp = GetXmlHttpObject()) {
		var url = "insertAddNewProject.php";
		url = url + param;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = addNewProjectStateChanged;
		xmlHttp.open("POST", url, true);
		xmlHttp.send(url);
	}
}

function addNewProjectStateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		if(trimStr(xmlHttp.responseText) == "successed") {
			alert("新项目添加成功!");
			reset();
		} else {
			alert("新项目添加失败！！！");
		}
	}
}


function onUpdateProject(param) {
	if(xmlHttp = GetXmlHttpObject()) {
		var url = "insertUpdateProject.php";
		url = url + param;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = updateProjectStateChanged;
		xmlHttp.open("POST", url, true);
		xmlHttp.send(url);
	}
}

function updateProjectStateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		if(trimStr(xmlHttp.responseText) == "successed") {
			alert("项目更新成功!");
		} else {
			alert("项目更新失败！！！");
		}
	}
}


function addProperty(param) {
	if(xmlHttp = GetXmlHttpObject()) {
		var url = "insertProperty.php";
		url = url + param;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = addPropertyStateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}
function addPropertyStateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		var sub = trimStr(xmlHttp.responseText).split(',');
		if(sub[0] == "successed") {
			alert("添加成功!");
			onPropertyTypeClick(sub[1]);
		} else if(sub[0] == "exist") {
			if(sub[1] == "platform") {
				alert("该平台已经存在，请不要重复添加！！");
			} else {
				alert("该项已经存在，请不要重复添加！！！");
				onPropertyTypeClick(sub[1]);
			}
		} else {
			alert("添加失败！！！");
		}
	}
}